//
//  BCConversionCurrencyCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2019/1/7.
//  Copyright © 2019 guoshikeji. All rights reserved.
//

#import "BCConversionCurrencyCell.h"

@implementation BCConversionCurrencyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.fd_enforceFrameLayout = true;
        self.backgroundColor = [UIColor clearColor];
        [self setupBaseSubviews];
    }
    return self;
}
- (void)setupBaseSubviews {
    self.titleLabel = [QMUILabel new];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.textColor = [UIColor qmui_colorWithHexString:@"#666666"];
    self.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
    [self.contentView addSubview:self.titleLabel];
    
    //
    self.contentLabel = [QMUILabel new];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.textColor = self.titleLabel.textColor;
    self.contentLabel.textAlignment = NSTextAlignmentRight;
    self.contentLabel.font = self.titleLabel.font;
    [self.contentView addSubview:self.contentLabel];
    //
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).offset(15.0);
        make.top.mas_equalTo(self.contentView);
        make.width.mas_equalTo(self.contentView).multipliedBy(2.0/5).offset(-20.0);
    }];
    //
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView);
        make.right.mas_equalTo(self.contentView).offset(-15.0);
        make.width.mas_equalTo(self.contentView).multipliedBy(3.0/5).offset(-20.0);
    }];
}




//

- (CGSize)sizeThatFits:(CGSize)size {
    CGFloat height = 0;
    //比较高度
    CGFloat titleWidth = size.width*(2.0/5)-20.0;
    CGFloat titleHeight = [self.titleLabel sizeThatFits:CGSizeMake(titleWidth, CGFLOAT_MAX)].height;
    //
    CGFloat contentWidth = size.width*(3.0/5)-20.0;
    CGFloat contentHeight = [self.contentLabel sizeThatFits:CGSizeMake(contentWidth, CGFLOAT_MAX)].height;
    //
    height += MAX(titleHeight, contentHeight);
    height += 15.0;
    return CGSizeMake(size.width, height);
}


- (void)setCellModel:(BConversionCellModel *)cellModel {
    _cellModel = cellModel;
    //
    self.titleLabel.text = BCLocalizedKey(cellModel.titleKey);
}

@end
